<template>
	<view class="content">
		
<view class="status-contents">
			<view class="status top-view"></view>
		</view>
		<!-- 页面标题 -->
		<!-- #ifdef APP-PLUS -->
		<view class="title-box" @click="back">
			<text class="title" >转出到预付款账户</text>
		</view>
		<!-- #endif -->
		
		<!-- 中间部分 -->
		<view class="buy-box">
			<view class="pay-method">
				<text class="num">转出金额</text>
				<input class="num_" v-model="money" placeholder="请输入转出金额"/>
			</view>
			<text class="more">转出金额不能低于{{min}}元</text>
		</view>
		
		<view class="confirm-btn" @click="paysub()">
			<text>确认转出</text>
		</view>
		<uni-password ref="secrity" @input="onInput" @confirm="onConfirms" v-if="pay_password">
			请输入6位支付密码
		</uni-password>
	</view>
</template>

<script>
	import uniIcon from "@/components/uni-icon/uni-icon.vue"
	import eonfox from '@/components/eonfox/eonfox.js';
	import fns from '@/components/eonfox/fns.js';
	import uniPassword from '@/components/ku3gitxdx-payment-password/ku3gitxdx-payment-password.vue'
	var ef=new eonfox()
	export default {
		data() {
			return {
				money:'',//转出金额，
				min:0,
				pay_password:false,
				type:0
			};
		},
		onLoad() {
			var _this=this
			ef.submit({
				request:{
					config:['APPLICATIONCONFIG'],
				},
				callback(data){
					var dataList=fns.checkError(data,'config').config.user_money_earning_transfer_user_money_help
					console.log('.......',dataList);
					if( !dataList ){
						return false;
					}
					if(!dataList.state){
						fns.err('该功能已关闭')
					}else{
						_this.min=dataList.min_user_money_earning/100
					}
					if(dataList.pay_password_state){
						console.log("开启了支付密码", dataList.pay_password_state);
						_this.type=1
					}else{
						console.log("关闭了支付密码", dataList.pay_password_state);
						_this.type=0
					}
					console.log('_this.type',_this.type)
				},
				error(err){
					fns.err('获取配置失败',err)
				}
			})
		},
		components:{
			uniIcon	,
			eonfox,
			fns,
			uniPassword
			
		},
		methods: {
			onInput(e) {
				//e.cancel = true;
				// console.log('onInput',e,e.cancel);
			},
			onConfirms(e) {
				var _this=this
				let password = e.value;
				console.log('password',password,password.length);
				if(password.length!=6){
					fns.err('请正确输入密码')
				}else{
					ef.submit({
						request:{s:['APPLICATIONORDERSELFUSERMONEYEARNINGTRANSFERUSERMONEYHELP',[{
							money_fen:_this.money*100,//转出金额
							pay_password:password
							}]]},
							callback:function(data){
								var fns_=fns.checkError(data,'s',function(errno,error){
									uni.showToast({
										title:error,
										icon:'none'
									})
								})
								console.log(fns_);
								if(fns_){
									uni.showToast({
										title:'转出成功',
										icon:'success',
										success() {
											setTimeout(function(){
												uni.navigateBack({
													delta:1
												})
											},1000)
										}
									})
								}
							},
							error:function(err){
								uni.showToast({
									title: JSON.stringify(err),
									icon: 'none'
								})
							}
					})
				}
			
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			paysub(){
				var _this=this;
				if(!/^[0-9]*$/.test(_this.money)||_this.money<=0||_this.money<_this.min){
					uni.showToast({
						title:'转出金额不可小于'+_this.min+'元',
						icon:'none'
					})
					return;
				}
				if(_this.type==0){
					_this.pay();
				}
				if(_this.type==1){
					_this.pay_password=true
				}
			},
			pay() {
				var	_this = this;
				console.log(_this.money,_this.min);
				ef.submit({
					request:{s:['APPLICATIONORDERSELFUSERMONEYEARNINGTRANSFERUSERMONEYHELP',[{
						money_fen:_this.money*100//转出金额
						}]]},
						callback:function(data){
							var fns_=fns.checkError(data,'s',function(errno,error){
								uni.showToast({
									title:error,
									icon:'none'
								})
							})
							console.log(fns_);
							if(fns_){
								uni.showToast({
									title:'转出成功',
									icon:'success',
									success() {
										setTimeout(function(){
											uni.navigateBack({
												delta:1
											})
										},1000)
									}
								})
							}
						},
						error:function(err){
							uni.showToast({
								title: JSON.stringify(err),
								icon: 'none'
							})
						}
				})
				
			},
		}
	}
</script>

<style>
	.status-contents{
		height: var(--status-bar-height);
		background-color: #f4f3f3;
	}
	.top-view{
		width: 100%;
		position: fixed;
		top: 0;
	}
	.status{
		height:var(--status-bar-height);
	}
</style>

<style scoped lang="stylus" ref="stylesheet/stylus">
	.content
		width 100%
		// overflow hidden
		.title-box
			width 100%
			height 60px
			color #333
			font-size 18px
			line-height 60px
			background-color #f4f3f3
			.icon
				width 40%
		.buy-box
			width 100%
			height 400px
			background-color #fff
			.pay-method
				width 95%
				height 30%
				color #444444
				margin 0 auto
				font-size 14px
				display flex
				justify-content center   // 水平居中
				align-items center       // 垂直居中
				flex-direction column
				border-bottom 1px solid #ccc
				text-align left !important
				.num
					width 100%
					height 30%
					line-height 40px
					display block
				.num_
					width 100%
					height 70%
					line-height 110px
					font-size 28px
					display block
			.buy-count
				width 95%
				height 30%
				color #444444
				margin 0 auto
				font-size 14px
				display flex
				justify-content center   // 水平居中
				align-items center       // 垂直居中
				flex-direction column
				border-bottom 1px solid #ccc
				text-align left !important
				
				.num
					width 100%
					height 30%
					line-height 40px
					display block
				.num_
					width 100%
					height 70%
					line-height 110px
					font-size 15px
					display block
			.need-money
				width 95%
				height 30%
				margin 0 auto
				font-size 14px
				color #444444
				display flex
				justify-content center   // 水平居中
				align-items center       // 垂直居中
				flex-direction column
				border-bottom 1px solid #ccc
				text-align left !important
				.need
					width 100%
					height 30%
					line-height 40px
				.input-box
					width 100%
					height 70%
					line-height 110px
					font-size 28px
					display flex
					justify-content center   // 水平居中
					align-items center       // 垂直居中
					flex-direction row
					.symbol
						color #333
					input
						padding 10px 0
						padding-left 10px
			.more
				display block
				width 95%
				color #444444
				font-size 14px
				margin 0 auto
		.confirm-btn
			width 95%
			height 55px
			color #fff
			margin 0 auto
			display flex
			justify-content center   // 水平居中
			align-items center
			background-color #F8A0A0
			border-radius 4px

</style>
